#include <bits/stdc++.h>
using namespace std;
int a[100000],h[100000],n;
int co()
{
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i-1;j;j--)
        {
            if(h[i]==h[j])
            {
                if(a[i]==a[j]) ans+=a[i];
                break;
            }
        }
    }
    return ans;
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t,ans,j;
    cin>>t;
    while(t--)
    {
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        memset(h,0,sizeof h),ans=0;
        while(1)
        {
            ans=max(co(),ans);
            h[n]++,j=n;
            while(h[j]==2) j--,h[j+1]=0,h[j]++;
            if(h[0]==1) break;
        }
        cout<<ans<<"\n";
    }
    return 0;
}
